-- @owner: @zhanghuan96
-- @date: 2024/12/18
-- @testpoint: 自定义函数嵌套，使用gms_UTILITY.FORMAT_ERROR_STACK函数
@conn PrimaryDbAmode;
--前置条件
drop extension if exists gms_utility;
create extension gms_utility;
--step1:创建自定义函数;expect:成功
drop function if exists func_format0009_01;
create or replace function func_format0009_01(a int, b int)
returns int as $$
declare
    res int := 0;
begin
    res = a / b;
    return res;
exception
    when others then
    raise exception 'expected exception';
end;
$$ language plpgsql;
/
--step2:创建自定义函数，函数嵌套上述函数;expect:成功
drop function if exists func_format0009_02;
create or replace function func_format0009_02(a int, b int)
returns int as $$
declare
    res int := 0;
begin
    res := func_format0009_01(a, b);
    return res;
exception
    when others then
    RAISE INFO 'INFO:%', gms_utility.format_error_stack();
    return -1;
end;
$$ language plpgsql;
/
--step3:调用函数;expect:成功
select func_format0009_02(100, 2);
--step4:调用函数;expect:成功
select func_format0009_02(100, 0);
--step5:清理环境;expect:成功
drop function if exists func_format0009_01;
drop function if exists func_format0009_02;
drop extension if exists gms_utility;